<?php
/***************************************************************************
   Coppermine 1.3.1 for CPG-Dragonfly™
  **************************************************************************
   Port Copyright (c) 2004-2005 CPG Dev Team
   http://dragonflycms.com/
  **************************************************************************
   v1.1 (c) by Grégory Demar http://coppermine.sf.net/
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
****************************************************************************/
if (!defined('CPG_NUKE')) { exit("You can't access this file directly..."); }

define('NO_HEADER', true);
require("modules/{$module_name}/include/load.inc");

try
{
	if (empty($_GET['picfile']) || false !== strpos($_GET['picfile'], '..')) {
		throw new Exception('invalid picfile');
	}

	$src_file = $CONFIG['fullpath'] . $_GET['picfile'];
	$new_size = $_GET->uint('size') ?: 48;

	$img = \Poodle\Image::open($src_file);
//	$img->setImageFormat('png');
	$img->thumbnailImage($new_size, $new_size, true);
	$img->setImageCompressionQuality(intval($CONFIG['jpeg_qual']));
	header('Content-type: '.$img->getImageMimeType());
	header('Connection: Close');
	echo $img;
}
catch (Exception $e)
{
	header("Content-type: image/gif");
	header("X-Image-Error: ".$e->getMessage());
	fpassthru(fopen($CPG_M_DIR.'/images/read_error48x48.gif', 'rb'));
}
exit;
